package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.DishPageQueryDTO;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Orders;
import com.sky.vo.DishVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Mapper
@Component
public interface OrderMapper {
//    根据id查询所有
    @Select("select * from orders where id =#{id}")
    Orders seleteAllById(Long id);


//    取消订单   完成订单 拒单   派送订单
    void updateOrder(Orders orders);

//    各个状态的订单数量统计
    @Select("select count(*) from orders where status = #{status}")
    Integer selectByStatus(Integer status);


//    接单
    @Update("update order set status = #{status} where id = #{id}")
    Integer updateConfirm(Long id,Integer status);

//    查询订单详情
    @Select("select * from orders where id =#{id}")
    OrderVO selectById(Long id);


//    订单搜索
    Page<Orders> page(OrdersPageQueryDTO pageQueryDTO);


//================= 以下为用户端  ===================

    //    历史订单查询
    Page<Orders> pageQuery(OrdersPageQueryDTO dto);
    //    取消订单

    void cancel(Orders orders);
//    用户下单

    void InsertOrder(Orders o);
//查询总订单数

    Integer getOrderCount(Map map);
//营业额

    Double sumTurnover(Map map);

    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);


    /**
     * 修改订单信息
     */
    void update(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     */
    @Select("select * from orders where number = #{orderNumber} ")
    Orders getByNumber(String orderNumber);

    List<Orders> getByStatusAndOrderTime(Integer pendingPayment, LocalDateTime localDateTime);

    List<Orders> getByStatusAndOrderEsTimated(Integer deliveryInProgress, LocalDateTime localDateTime);
}
